home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Macintosh Drag and Drop / Demo Applications / Dragster / DragText Sources / Offscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-03  |  1.6 KB  |  74 lines  |  [TEXT/KAHL]

  1. /*
  2.  *        Offscreen.c
  3.  *
  4.  *        12/30/94    JML        Code now compiles with Universal interfaces.
  5.  *
  6.  */
  7.  
  8.  
  9. #include <Memory.h>
  10. #include <QDOffscreen.h>
  11. #include "Offscreen.h"
  12.  
  13.  
  14. WindowOffscreen *DrawOffscreen(WindowPtr theWindow)
  15.  
  16. {    WindowOffscreen        *theOffscreen;
  17.     GWorldPtr            theWorld;
  18.     short                depth;
  19.     Rect                globalRect;
  20.  
  21.     if ((theOffscreen = (WindowOffscreen *) NewPtr(sizeof(WindowOffscreen))) == 0L)
  22.         return(0L);
  23.  
  24.     SetPort(theWindow);
  25.     GetGWorld(&theOffscreen->windowPort, &theOffscreen->windowDevice);
  26.  
  27.     globalRect = theWindow->portRect;
  28.     LocalToGlobal((Point *) &globalRect.top);
  29.     LocalToGlobal((Point *) &globalRect.bottom);
  30.  
  31.     if (NewGWorld(&theWorld, 0, &globalRect, 0L, 0L, 0) == noErr) {
  32.  
  33.         SetGWorld(theWorld, 0L);
  34.         if (! LockPixels(theWorld->portPixMap)) {
  35.             DisposeGWorld(theWorld);
  36.             DisposePtr((Ptr) theOffscreen);
  37.             return(0L);
  38.         }
  39.  
  40.         CopyBits(&theWindow->portBits,
  41.                  &((GrafPtr) theWorld)->portBits,
  42.                  &theWindow->portRect,
  43.                  &theWorld->portRect,
  44.                  srcCopy, 0L);
  45.  
  46.         theOffscreen->offscreenWorld = theWorld;
  47.         return(theOffscreen);
  48.  
  49.     } else {
  50.  
  51.         DisposePtr((Ptr) theOffscreen);
  52.         return(0L);
  53.  
  54.     }
  55. }
  56.  
  57.  
  58.  
  59. void DrawOnscreen(WindowOffscreen *theOffscreen)
  60.  
  61. {
  62.     if (theOffscreen) {
  63.         SetGWorld(theOffscreen->windowPort, theOffscreen->windowDevice);
  64.         CopyBits(&((GrafPtr) theOffscreen->offscreenWorld)->portBits,
  65.                  (BitMapPtr)&(theOffscreen->windowPort)->portPixMap,
  66.                  &theOffscreen->offscreenWorld->portRect,
  67.                  &theOffscreen->windowPort->portRect,
  68.                  srcCopy, 0L);
  69.         UnlockPixels(theOffscreen->offscreenWorld->portPixMap);
  70.         DisposeGWorld(theOffscreen->offscreenWorld);
  71.         DisposePtr((Ptr) theOffscreen);
  72.     }
  73. }
  74.